package com.hillky;

import com.hillky.core.HeartbeatDetector;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

@Slf4j
public class ConsumerApplication {
    public static void main(String[] args) {

        //   想尽一切办法获取代理对象,使用ReferenceConfig进行封装
        ReferenceConfig<HelloYrpc> reference = new  ReferenceConfig();
        reference.setInterface(HelloYrpc.class);


        //消费这要做的
        //1.连接注册中心
        //2.拉取服务列表
        //3.选择一个服务建立连接
        //4.发送请求 携带一些信息（接口名，参数列表，方法的名字），获得结果

        YrpcBootstrap.getInstance()
                .application("first-yrpc-consumer")
                .registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
                .serialize("hessian")
                .compress("gzip")
                .group("primary")
                .reference(reference);

        HelloYrpc helloYrpc = reference.get();

//        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
//        for (int i = 0; i < 10; i++) {
//            String sayHi = helloYrpc.sayHi("你好yrpc");
//            log.info("sayHi-->{}",sayHi);
//        }

        while (true){
//            try {
//                Thread.sleep(20000);
//                System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }

            for (int i = 0; i < 499; i++) {
                String sayHi = helloYrpc.sayHi("你好yrpc");
                log.info("sayHi-->{}",sayHi);
            }



//            HeartbeatDetector.detectHeartbeat(HelloYrpc.class.getName());
        }






    }
}
